﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IdentityModel.Claims;

namespace SharpShare.IdentityModel {
    public static class ClaimExtensions {
        public static object GetClaimResource(this IEnumerable<ClaimSet> claimSets, ClaimSet issuer, string claimType, string right) {
            Claim claim = claimSets.GetClaim(issuer, claimType, right);
            if (claim == null)
                return null;
            return claim.Resource;
        }
        public static Claim GetClaim(this IEnumerable<ClaimSet> claimSets, ClaimSet issuer, string claimType, string right) {
            Claim claim = claimSets
                .Where(c => c.Issuer == issuer)
                .SelectMany(c => c.FindClaims(claimType, right))
                .FirstOrDefault();
            return claim;
        }
    }
}
